from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from requests import Response
from rest_framework.generics import GenericAPIView, ListAPIView, ListCreateAPIView
from rest_framework.mixins import ListModelMixin, CreateModelMixin
from rest_framework.viewsets import ModelViewSet
from rest_framework import viewsets

import requests

BaseUrl = 'http://81.70.79.122:6800'
defaultProject = 'designdb_spider'
defaultspider = 'wipoSpider'


def WipoInfo_listspiders(request):
    # 使用API代理服务提高访问稳定性
    url = f"{BaseUrl}/listspiders.json?project={defaultProject}"
    print("url::::", url)
    response = requests.get(url)

    if response.status_code == 200:
        print("Response Data:", response.json())
    return JsonResponse(response.json(), safe=False)


def WipoInfo_schedule(request):
    # 使用API代理服务提高访问稳定性
    url = f"{BaseUrl}/schedule.json?project=designdb_spider?project={defaultProject}&spider={defaultspider}"
    print("url::::", url)
    response = requests.post(url)
    if response.status_code == 200:
        print("Response Data:", response.json())
    return JsonResponse(response.json(), safe=False)
def WipoInfo_listjobs(request):
    # 使用API代理服务提高访问稳定性
    url = f"{BaseUrl}/listjobs.json?project={defaultProject}"
    print("url::::", url)
    response = requests.get(url)
    if response.status_code == 200:
        print("Response Data:", response.json())
    return JsonResponse(response.json(), safe=False)
